<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="数据日期" prop="sjrq">
        <el-date-picker
          v-model="queryParams.sjrq"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="date"
          range-separator="-"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="商户名称" prop="mcname">
        <el-input
          v-model="queryParams.mcname"
          placeholder="请输入商户名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="管户机构" prop="deptid">
        <el-select v-model="queryParams.deptid" clearable placeholder="请选择"><el-option v-for="item in orgList" :key="item.value" :label="item.orgName" :value="item.orgId"></el-option></el-select>
      </el-form-item>
      <el-form-item label="优质商户" prop="sfyz">
        <el-select v-model="queryParams.sfyz" placeholder="请选择是否优质商户">
          <el-option label="是" value="Y"></el-option>
          <el-option label="否" value="N"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="负责人名称" prop="respname">
        <el-input
          v-model="queryParams.respname"
          placeholder="请输入负责人名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责人证件" prop="zjhm">
        <el-input
          v-model="queryParams.zjhm"
          placeholder="请输入负责人证件"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['buss:yzsh:add']"
        >新增</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['buss:yzsh:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="yzshList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="数据日期" width="100" align="center" prop="sjrq" :formatter="sjrqFormat" />
            <el-table-column label="机构名称" width="250" align="center" prop="deptname" :show-overflow-tooltip="true" :formatter="deptnameFormat" />
            <el-table-column label="商户号" width="100" align="center" prop="mcid"   />
            <el-table-column label="商户名称" width="150" align="center" :show-overflow-tooltip="true" prop="mcname"   />
            <el-table-column label="商户负责人名称" align="center" prop="respname"  />
            <el-table-column label="电话号码" width="110" align="center" prop="chargemobile"   />
            <el-table-column label="开户日" align="center" prop="khr"  />
            <el-table-column label="计算月" align="center" prop="jsy"  />
            <el-table-column label="交易笔数" align="center" prop="jybs"  />
            <el-table-column label="交易金额" align="center" prop="amount"   />
            <el-table-column label="月均交易笔数" align="center" prop="yjjybs"   />
            <el-table-column label="月均交易金额" align="center" prop="yjjyje"   />
            <el-table-column label="月均大于300笔" align="center" prop="yjbsdy300"   />
            <el-table-column label="月均大于3000元" align="center" prop="yjjedy3000"   />
            <el-table-column label="口径一差笔数" align="center" prop="kjybs"   />
            <el-table-column label="口径一差金额" align="center" prop="kjyje"   />
            <el-table-column label="月均大于30笔" align="center" prop="yjbsdy30"   />
            <el-table-column label="月均大于10000元" align="center" prop="yjjedy10000"   />
            <el-table-column label="口径二差笔数" align="center" prop="kjebs"  />
            <el-table-column label="口径二差金额" align="center" prop="kjeje"  />
            <el-table-column label="月均大于10笔" align="center" prop="yjbsdy10"   />
            <el-table-column label="月均大于50000元" align="center" prop="yjjedy50000"   />
            <el-table-column label="口径三差笔数" align="center" prop="kjsabs"   />
            <el-table-column label="口径三差金额" align="center" prop="kjsaje"   />
            <el-table-column label="月均大于1笔" align="center" prop="yjbsdy1"   />
            <el-table-column label="月均大于200000元" align="center" prop="yjjedy200000"   />
            <el-table-column label="口径四差笔数" align="center" prop="kjsibs"   />
            <el-table-column label="口径四差金额" width="110"  align="center" prop="kjsije"   />
            <el-table-column label="是否优质" align="center" prop="sfyz"  />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改优质商户对话框  -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listYzsh, getYzsh, delYzsh, addYzsh, updateYzsh } from "@/api/buss/yzsh";
import { orglist, queryManager } from '@/api/buss/sqzxt';

export default {
  name: "Yzsh",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 优质商户表格数据
      yzshList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否优质商户  0否 1是字典
      sfyzshOptions: [],
      orgList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sjrq: null,
        deptid: null,
        deptname: null,
        mcid: null,
        mcname: null,
        respname: null,
        chargemobile: null,
        khr: null,
        jsy: null,
        jybs: null,
        amount: null,
        yjjybs: null,
        yjjyje: null,
        yjbsdy300: null,
        yjjedy3000: null,
        kjybs: null,
        kjyje: null,
        yjbsdy30: null,
        yjjedy10000: null,
        kjebs: null,
        kjeje: null,
        yjbsdy10: null,
        yjjedy50000: null,
        kjsabs: null,
        kjsaje: null,
        yjbsdy1: null,
        yjjedy200000: null,
        kjsibs: null,
        kjsije: null,
        sfyz: null,
        deptid: "",
        sfyz: ""
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();

    this.getDicts("sys_buss_type").then(response => {
      this.sfyzshOptions = response.data;
    });

  },
  methods: {
    /** 查询优质商户列表 */
    getList() {
      this.loading = true;
      listYzsh(this.queryParams).then(response => {
        this.yzshList = response.rows;
        this.total = response.total;
        this.loading = false;
      });

      //下拉机构
      orglist().then(response => {
        this.orgList = response.rows;
      });
    },
    // 是否优质商户  0否 1是字典翻译
    sfyzshFormat(row, column) {
      return this.selectDictLabel(this.sfyzshOptions, row.sfyzsh);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        sjrq: null,
        deptid: null,
        deptname: null,
        mcid: null,
        mcname: null,
        respname: null,
        chargemobile: null,
        khr: null,
        jsy: null,
        jybs: null,
        amount: null,
        yjjybs: null,
        yjjyje: null,
        yjbsdy300: null,
        yjjedy3000: null,
        kjybs: null,
        kjyje: null,
        yjbsdy30: null,
        yjjedy10000: null,
        kjebs: null,
        kjeje: null,
        yjbsdy10: null,
        yjjedy50000: null,
        kjsabs: null,
        kjsaje: null,
        yjbsdy1: null,
        yjjedy200000: null,
        kjsibs: null,
        kjsije: null,
        sfyz: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.deptid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加优质商户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const deptid = row.deptid || this.ids
      getYzsh(deptid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改优质商户";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.deptid != null) {
            updateYzsh(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addYzsh(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const deptids = row.deptid || this.ids;
      this.$confirm('是否确认删除优质商户编号为"' + deptids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delYzsh(deptids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('buss/yzsh/export', {
        ...this.queryParams
      }, `buss_yzsh.xlsx`)
    }
  }
};
</script>
